Skip to content

Conversation

@bimakw
Copy link
Contributor

@bimakw bimakw commented Dec 20, 2025

Summary

This PR adds support for closing keywords (closes, fixes, reopens, etc.) with full URL references in markdown links.

Before:

  • closes #123 ✅ works
  • closes org/repo#123 ✅ works
  • Closes [this issue](https://gitea.io/user/repo/issues/123) ❌ didn't work
  • Fixes [#456](https://gitea.io/org/project/issues/456) ❌ didn't work

After:
All of the above now work correctly.

Problem

When users reference issues using full URLs in markdown links (e.g., Closes [this issue](https://gitea.io/user/repo/issues/123)), the closing keywords were not detected. This was because the URL processing code explicitly stated:

// Note: closing/reopening keywords not supported with URLs

Both methods of writing the reference render the same in the UI, so users expected the closing keywords to behave the same.

Solution

The fix works by:

  1. Passing the original (unstripped) content to findAllIssueReferencesBytes
  2. When processing URL links from markdown, finding the URL position in the original content
  3. For markdown links [text](url), finding the opening bracket [ position
  4. Using that position to detect closing keywords before the link

Testing

Added test cases for:

  • Closes [this issue](url) - single URL with closing keyword
  • This fixes [#456](url) - keyword in middle of text
  • Reopens [PR](url) - reopen keyword with pull request URL
  • Multiple URLs where only one has a closing keyword

All existing tests continue to pass.

Fixes #27549

Previously, closing keywords (closes, fixes, etc.) only worked with
short references like `closes go-gitea#123` or `closes org/repo#123`.

This commit adds support for closing keywords with full URL references
in markdown links, such as:
- `Closes [this issue](https://gitea.io/user/repo/issues/123)`
- `Fixes [go-gitea#456](https://gitea.io/org/project/issues/456)`

The fix works by:
1. Passing the original content to findAllIssueReferencesBytes
2. When processing URL links, finding the URL position in original content
3. For markdown links [text](url), finding the opening bracket position
4. Using that position to detect closing keywords before the link

Fixes go-gitea#27549
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Dec 20, 2025
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label Dec 20, 2025
@lunny lunny added this to the 1.26.0 milestone Dec 20, 2025
@lunny lunny added the type/enhancement An improvement of existing functionality label Dec 20, 2025
@silverwind
Copy link
Member

Could you also add test cases for bare URL? I'm pretty sure they already work, but good add more tests:

Fixes https://gitea.io/org/project/issues/456
Fixes: https://gitea.io/org/project/issues/456
Closes https://gitea.io/org/project/issues/456
Closes: https://gitea.io/org/project/issues/456

Added test coverage for bare URLs with closing keywords:
- Fixes https://...
- Fixes: https://...
- Closes https://...
- Closes: https://...

As suggested by @silverwind
@bimakw
Copy link
Contributor Author

bimakw commented Dec 24, 2025

@silverwind Added test cases for bare URLs with closing keywords. All tests passing.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Dec 24, 2025
@bimakw
Copy link
Contributor Author

bimakw commented Dec 24, 2025

When idx is 0, it means the URL is at the very beginning of the content. In that case, there's nothing before it where a closing keyword like "Closes" or "Fixes" could exist. The findActionKeywords function looks at content[:start], so if start is 0, it searches an empty slice and returns XRefActionNone anyway.

I can change it to idx >= 0 if you prefer - the result would be the same but maybe clearer to read. Let me know.

@bimakw
Copy link
Contributor Author

bimakw commented Dec 25, 2025

/test-all

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Dec 25, 2025
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Dec 26, 2025
@lunny lunny changed the title fix: support closing keywords with URL references Support closing keywords with URL references Dec 26, 2025
@lunny lunny merged commit 83527d3 into go-gitea:main Dec 27, 2025
24 checks passed
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Dec 27, 2025
zjjhot added a commit to zjjhot/gitea that referenced this pull request Dec 29, 2025
* giteaofficial/main:
  [skip ci] Updated translations via Crowdin
  Use gitrepo's push function (go-gitea#36245)
  Support closing keywords with URL references (go-gitea#36221)
  Add an option to automatically verify SSH keys from LDAP (go-gitea#35927)
  remove nolint (go-gitea#36252)
  Use the requested host for LFS links (go-gitea#36242)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/go Pull requests that update Go code type/enhancement An improvement of existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Closing keywords do not work with URLs

4 participants